public class Test {
    public static void fun(int x){
        x = 100;
        System.out.println("x = " + x);
    }//不改变实参的数值

    public static void fun(int[] array){
        array[0] = 10;
        System.out.println("array[0] = " + array[0]);
    }

    public static int[] copyof(int[] array){
        int[] ret = new int[array.length];
        for(int i = 0; i < array.length; i++){
            ret[i] = array[i];
        }
        return ret;
    }
    public static int find(int[] array, int i){
        for(int j = 0; j < array.length; j++){
            if(array[j] == i){
                return j;
            }
        }
        return -1;//总的返回语句
    }//顺序查找

    public static void main(String[] args) {
        //数组顺序查找\
        int[] arr = new int[]{1,2,9,30,4,67};
        int k = find(arr,30);
        System.out.println(k);
    }


    public static void main6(String[] args) {
        //数组拷贝
        //要知道数组长度 在复制
        int[] arr = new int[]{1,2,3};
        System.out.print(copyof(arr));
    }

    public static void main5(String[] args) {
        int[] arr = {1, 2, 4};

        fun(arr);
        System.out.println("arr = " + arr[0]);
    }//数组引用的是地址 所以实参数组也被改变了
    public static void main4(String[] args) {
        int i = 10;
        fun(i);
        System.out.println("i = " + i);
    }

    public static void main3(String[] args) {
        int[] array1 = new int[3];
        array1[0] = 10;
        array1[1] = 20;
        array1[2] = 30;



        int[] array2 = new int[]{1,2,3,4,5};
        array2[0] = 100;
        array2[1] = 200;


        array1 = array2;//数组1引用了数组2 此时两个是同一个数组
        array1[2] = 300;
        array1[3] = 400;
        array2[4] = 500;
        for (int i = 0; i < array2.length; i++) {
            System.out.println(array2[i]);
        }
    }
    public static void main2(String[] args) {
        //创建数组
        int[] arr = new int[]{1,2,3,4,5,6,7,8,9,10};
        /*for(int i = 0; i < arr.length; i++){
            System.out.print(arr[i]);
            System.out.print(" ");
        }*/
        /*for(int x:arr){
            System.out.print(arr[x]);
            System.out.print(" ");
        }*/

    }
}
